from save import doc_to_vectorstore
from query import query_rag

import logging

logging.basicConfig(
    level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s"
)
logger = logging.getLogger(__name__)

if __name__ == "__main__":

    doc_to_vectorstore("过秦论.txt")

    query = "秦国是怎么变成强国的？"
    logger.info(f"用户查询:{query}")
    try:
        answer = query_rag(query, n_results=3)
        print(f"答案:", answer)
    except ValueError as e:
        print(f"错误:{e}")
    except Exception as e:
        print(f"错误:{e}")
